//
//  DebitStyleButton.swift
//  IDF
//
//  Created by 陈徐挺 on 24/03/2018.
//  Copyright © 2018 Jesse.chen. All rights reserved.
//

import UIKit
import Reusable

class DebitStyleButton: UIView, NibOwnerLoadable {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    @IBOutlet weak var selectImageView: UIImageView!
    @IBOutlet weak var clickBtn: UIButton!
    var index: Int = 0
    var clickCallback : ((_ index : Int) -> Void)!
    var selected: Bool = false
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.loadNibContent()
    }
    
    @IBAction func click(_ sender: UIButton) {
        if let cb = clickCallback  {
            cb(index)
        }
    }
    
    func setSelect(_ selectIndex: Int) {
        if selectIndex == index {
            selectImageView.isHidden = false
            clickBtn.layer.borderWidth = 2
            clickBtn.layer.borderColor = UIColor(hexString: "#8cadf5")?.cgColor
            clickBtn.backgroundColor = UIColor(hexString: "#f8faff")
        } else {
            selectImageView.isHidden = true
            clickBtn.layer.borderWidth = 1
            clickBtn.layer.borderColor = UIColor(hexString: "#bebebe")?.cgColor
            clickBtn.backgroundColor = UIColor(hexString: "#ffffff")
        }
    }
    
    
}
